import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text ,RichText } from '@tarojs/components'
import CommonJs from '../../utils/common'
import '../../assets/common.scss'
import foot01 from '../../assets/kedouimg01/foot11.png'
import foot01c from '../../assets/kedouimg01/foot11c.png'
import foot02 from '../../assets/kedouimg01/foot08.png'
import foot02c from '../../assets/kedouimg01/foot08c.png'
import foot03 from '../../assets/kedouimg01/foot07.png'
import foot03c from '../../assets/kedouimg01/foot07c.png'
import foot04 from '../../assets/kedouimg01/foot4.png'
import foot04c from '../../assets/kedouimg01/foot4c.png'
import foot05 from '../../assets/kedouimg01/foot09.png'
import foot05c from '../../assets/kedouimg01/foot09c.png'
export default class footer extends Component {	
 constructor(props) {
    super(props);
    this.state = {
		nav:0,
		isIphoneX:0,
		noshow:CommonJs.getshow(),
      	noshow1:CommonJs.getshow()
    }
  }

  componentWillMount () {
  	const app = Taro.getApp();
  	let isIphoneX = app.globalData.isIphoneX;
  	
  	this.setState({
     	nav:this.props.porpNav,
     	isIphoneX:isIphoneX
   })
  	this.getshopid();
  	this.getshow()
  }
  componentDidShow () {

  }
  shouldComponentUpdate () {
  }
  componentWillUnmount () {

  }
  getshow(){
  	var url='/advert/papi/v1.9/advert/advert/state'
  	var _this=this
  	CommonJs.ajaxRequest(url,'','GET',function(res){
		_this.setState({
	      noshow:res.data.type
	    })
  	},"wfw")
  }
  open(url,type){
  	if(type){
  		 if (Taro.getEnv() === Taro.ENV_TYPE.WEAPP) {
	      this.$preload({
		      type:type
		    })
	    }
	}
  	if(url=='/pages/activity/activity'){
  		var id=Taro.getStorageSync('dateinfo').qid
  		url='/pages/activity/activity?scene='+id;
  	}
  	else{
  		var shopid=Taro.getStorageSync('shopId')
  		if(!shopid){
	  		Taro.showToast({
				title:'该群还未开通商城业务',
				icon: 'none',
				duration: 1500
			})
	  		return false;
	  	}
  	}
    CommonJs.open(url);
  }
  getshopid(url){
  	Taro.showToast({
		title:'加载中',
		icon: 'none',
		duration: 1000
	})
	var _this=this;
	var  qid=Taro.getStorageSync('dateinfo').qid;
	if(qid){
		var dates = {
		  clusterId: qid
		}
		CommonJs.ajaxRequest('/clusterShop/getClusterShopByclusterId',dates,'GET',function(res){
			if(res.content&&res.content.shopId){
				Taro.setStorage({key:'shopId',data:res.content.shopId})
	    		Taro.setStorage({key:'dealerId',data:res.content.dealerId})

			}
			else{
				Taro.setStorage({key:'shopId',data:''})
				Taro.setStorage({key:'dealerId',data:''})
			}

		})
	}
  }
  render () {
	const nav=this.state.nav;
    return(
     <View className='footer' style={this.state.noshow==this.state.noshow1?'display:none':this.state.isIphoneX==1?'padding-bottom:58rpx;display:flex;':'display:flex;'}>
		<View className={nav==0?'footer-dl footer-dlcur':'footer-dl'} onClick={this.open.bind(this,'/pages/mall/shopindex')}>
			<View className='footer-dt'>
				<Image className='footer-img' mode='widthFix' src={nav==0?foot01c:foot01}></Image>
			</View>
			<View className='footer-dd'>首页</View>
		</View>
		<View className={nav==1?'footer-dl footer-dlcur':'footer-dl'}  onClick={this.open.bind(this,'/pages/mall/goodscat')}>
			<View className='footer-dt'>
				<Image className='footer-img' mode='widthFix' src={nav==1?foot02c:foot02}></Image>
			</View>
			<View className='footer-dd'>分类</View>
		</View>
		<View className={nav==2?'footer-dl footer-dlcur':'footer-dl'} onClick={this.open.bind(this,'/pages/activity/activity')}>
			<View className='footer-dt'>
				<Image className='footer-img' mode='widthFix' src={nav==2?foot03c:foot03}></Image>
			</View>
			<View className='footer-dd'>社群生活</View>
		</View>
		<View className={nav==3?'footer-dl footer-dlcur':'footer-dl'} onClick={this.open.bind(this,'/pages/mall/shopcar')}>
			<View className='footer-dt'>
				<Image className='footer-img' mode='widthFix' src={nav==3?foot04c:foot04}></Image>
			</View>
			<View className='footer-dd'>购物车</View>
		</View>
		<View className={nav==4?'footer-dl footer-dlcur':'footer-dl'}  onClick={this.open.bind(this,'/pages/my/my')}>
			<View className='footer-dt'>
				<Image className='footer-img' mode='widthFix' src={nav==4?foot05c:foot05}></Image>
			</View>
			<View className='footer-dd'>我的</View>
		</View>
	</View>
    )
  }
}